package com.mzy.linear_struct.面试150题;

/**
 * @Author: mizy3
 * @Date: 2024/08/16/下午3:56
 * @Description:
 */
public class Pro83删除排序链表中的重复元素 {
/*    public ListNode deleteDuplicates(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;

        fast = fast.next;

        //   s
        // 1 2 2 2 3 3 4
        //         f
        while (fast != null) {
            while (fast != null && slow.val == fast.val) {
                fast = fast.next;
            }
            slow.next = fast;
            slow = fast;
            if (fast != null) {
                fast = fast.next;
            }
        }


        return head;
    }*/

    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;

        //   s
        // 1 2 2 2 3 3 4
        //         f
        while (cur != null && cur.next != null) {
            if(cur.val == cur.next.val){
                cur.next = cur.next.next;
            }else {
                cur = cur.next;
            }
        }


        return head;
    }
}
